﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using LoungeRepo.Contracts.Core;
using LoungeRepo.Core.Extensions;
using NUnit.Framework;
using Rhino.Mocks;

namespace Test.LoungeRepo.Core.Extensions
{
    [TestFixture]
    public class ILoungeRepositoryExtensions
    {
        [Test]
        public void Iterate_entities_in_repo()
        {
            string repoPath = Environment.CurrentDirectory + @"\testrepo";
            RepoHelpers.CreateMockEntityFile(repoPath, "0.entity");
            RepoHelpers.CreateMockEntityFile(repoPath + "\\part1", "1a.entity");
            RepoHelpers.CreateMockEntityFile(repoPath + "\\part2", "2a.entity");
            RepoHelpers.CreateMockEntityFile(repoPath + "\\part2", "2b.entity");
            RepoHelpers.CreateMockEntityFile(repoPath + "\\part2\\part22", "22a.entity");
            Directory.CreateDirectory(repoPath + "\\empty");

            var rit = new RepoEntityFileIterator();
            var entityFilenames = rit.Collect(repoPath);

            Assert.AreEqual(5, entityFilenames.Count());
            Assert.AreEqual("0.entity", Path.GetFileName(entityFilenames.First()));
            Assert.AreEqual("22a.entity", Path.GetFileName(entityFilenames.Last()));

            Directory.Delete(repoPath, true);
        }
    }
}
